﻿@{
    ViewBag.Title = "添加项目";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model LY.Entity.R_Project

<script src="~/Content/assets/app/common/ajaxupload.js"></script>
<link href="~/Content/validform.css" rel="stylesheet" />
<script src="~/Scripts/Validform_v5.3.2_min.js"></script>
<script src="~/Scripts/Validform_Datatype.js"></script>
<link href="~/Content/editor/themes/default/default.css" rel="stylesheet" />
<script src="~/Content/editor/kindeditor-min.js"></script>
<script src="~/Content/editor/lang/zh_CN.js"></script>

<script type="text/javascript">
    function OnSuccess(msg) {
        if (msg.Status == 1) {
            window.location.href = msg.Data;
        } else {
            $.dialog.alert(msg.Message);
            return false;
        } 
    }
    //初始化  
    var g_AjxTempDir = "/FileUpload/";
    function init(img, show, file, path) {
        //初始化图片上传  
        var btnImg = img;
        var img = show;
        var TitlePic = "111";
        var Pictures = "111";
        var fileName = file;
        g_AjxUploadImg(btnImg, img, TitlePic, Pictures, fileName, path);
    }
    //图片上传  
    function g_AjxUploadImg(btn, img, TitlePic, Pictures, fileName, path) {

        var button = btn, interval;
        new AjaxUpload(button, {
            action: path,
            data: {},
            name: 'myfile',
            onSubmit: function (file, ext) {
                if (!(ext && /^(jpg|JPG|png|PNG|gif|GIF)$/.test(ext))) {
                    alert("您上传的图片格式不对，请重新选择！");
                    return false;
                }
            },
            onComplete: function (file, response) {
                flagValue = response;
                if (flagValue == "-1") {
                    alert("您上传的图片格式不对，请重新选择！");
                }
                else if (flagValue == "-2") {
                    alert("您上传的图片大于200K，请重新选择！");
                }
                else if (flagValue == "-3") {
                    alert("图片上传失败！");
                }
                else {

                    var strs = new Array();
                    strs = response.split("/");

                    var Pictures2 = "";
                    var fileName2 = "";
                    for (var i = 0; i < strs.length; i++) {
                        if (i == 0) {
                            TitlePic.value = strs[i];
                        } else if (i == 1) {
                            Pictures.value = strs[i];
                            Pictures2 = strs[i];

                        } else if (i == 2) {
                            fileName2 = strs[i];
                        }
                    }
                    img.src = g_AjxTempDir + fileName2 + "/" + Pictures2;
                    fileName.value = g_AjxTempDir + fileName2 + "/" + Pictures2;
                }
            }
        });
    }

    //编辑器
    KindEditor.ready(function (K) {
        window.editor = K.create('#ProjectDetails', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            minWidth: 350,
            minHeight: 600,
            allowFileManager: true,
            afterBlur: function () {
                this.sync();
            }
        });
    });
    $(function () {
        //验证初始化
        $("form").Validform({
            tiptype: 3
        });
        var btnImg = document.getElementById("btnUploadImg");
        var fileName = document.getElementById("fileName");
        var img = document.getElementById("imgShow");
        var btnImg1 = document.getElementById("btnUploadImg1");
        var fileName1 = document.getElementById("fileName1");
        var img1 = document.getElementById("imgShow1");
        var btnImg2 = document.getElementById("btnUploadImg2");
        var fileName2 = document.getElementById("fileName2");
        var img2 = document.getElementById("imgShow2");
        init(btnImg, img, fileName, options.uploadUrl);
        init(btnImg1, img1, fileName1, options.uploadUrl2);
        init(btnImg2, img2, fileName2, options.uploadUrl);
    });

    function begin() {
        var fileName = document.getElementById("fileName").value;
        var fileName1 = document.getElementById("fileName1").value;
        var fileName2 = document.getElementById("fileName2").value;
        if (fileName == "") {
            alert("请上传首页图片！");
            return false;
        } else if (fileName1 == "") {
            alert("请上传频道推荐图片！");
            return false;
        } else if (fileName2 == "") {
            alert("请上传项目列表图片！");
            return false;
        }
    }

    //图片上传初始化
    var util = {};
    var options = {
        uploadUrl: "@Url.Action("UploadImg", "Helper")",
        uploadUrl2: "@Url.Action("UploadImg2", "Helper")"
    };

</script>
<style>
    #btnUploadImg, #btnUploadImg1, #btnUploadImg2 {
        text-align: center;
        line-height: 20px;
        height: 20px;
        margin: 0px;
        padding: 0px;
        border: 0px;
        float: left;
        width: 130px;
        height: 25px;
        font-size: 10pt;
    }

    em {
        float: left;
        margin: 0px 10px;
    }
</style>

<div class="line10"></div>
<div class="container">
    <div class="order-process">
        <ul>
            <li class="active">项目及发起人信息</li>
            <li>回报设置</li>
            <li>确认信息</li>
            <li>完成</li>
        </ul>
    </div>
    @using (Ajax.BeginForm("SaveProject", "Project", new AjaxOptions() { OnSuccess = "OnSuccess", OnBegin = "begin" }))
    {
        <div class="additem">
            <input type="hidden" id="Id" name="Id" value="@Model.Id"/>
            <input type="hidden" id="AddTime" name="AddTime" value="@Model.AddTime"/>
            <input type="hidden" id="MemberId" name="MemberId" value="@Model.MemberId"/>
            <input type="hidden" id="ProjectStatus" name="ProjectStatus" value="@Model.ProjectStatus"/>

            <h4 id="editInfo">项目信息</h4>
            <dl>
                <dt>项目类型：</dt>
                <dd>
                    @Html.ResourceRadioList("ProjectClass", "ProjectType", Model.ProjectClass == 0 ? 1 : Model.ProjectClass, true)
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;项目名称：</dt>
                <dd>
                    <input type="text" class="input normal1" id="ProjectName" name="ProjectName"  placeholder="不多于60个字" datatype="*,s0-60" value="@Model.ProjectName" />
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;一句话说明：</dt>
                <dd>
                    <input type="text" class="input normal1" id="ProjectAdWord" datatype="*" placeholder="请用一句话概括项目内容（不多于200字）" name="ProjectAdWord" value="@Model.ProjectAdWord" />
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;筹资金额：</dt>
                <dd>
                    <input type="text" class="input txt" id="Amount" datatype="num" placeholder="不少于XX元" name="Amount" nullmsg="请输入筹资金额" value="@(Model.Amount.ToString() == "0" ? "" : Model.Amount.ToString())" placeholder="不少于XX元"/>元
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;筹资天数：</dt>
                <dd>
                    <input type="text" class="input txt" id="CollectDays" datatype="n" name="CollectDays" value="@(Model.CollectDays.ToString() == "0" ? "" : Model.CollectDays.ToString())" placeholder="10~60天"/>天
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;项目简介：</dt>
                <dd>
                    <textarea id="ProjectSummary" class="input normal1" rows="4" name="ProjectSummary" datatype="*">@Model.ProjectSummary</textarea>
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;项目详情：</dt>
                <dd>
                    <input type="text" class="input normal1" id="ProjectDetails" name="ProjectDetails" datatype="*" value="@Model.ProjectDetails" />
                </dd>
            </dl>
            <dl>
                <dt>视频介绍：</dt>
                <dd>
                    <input type="text" class="input normal1" id="VideoAddr" name="VideoAddr"  value="@Model.VideoAddr"/></dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;首页图片：</dt>
                <dd>
                    <div class="uploadImg">
                        <input type="button" id="btnUploadImg" value="上传首屏图片" class="button" /><em>支持jpg、jpeg、png、gif格式，大小：650 X 500px</em>

                    </div>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <img id="imgShow" style="width: 650px; height: 500px" src="@Model.ProjectThumImage" />
                    <input type="hidden" id="fileName" name="ProjectThumImage" value="@Model.ProjectThumImage"/>
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;频道推荐图片：</dt>
                <dd>
                    <div class="uploadImg">
                        <input type="button" id="btnUploadImg1" value="上传频道推荐图片" class="button" /><em>支持jpg、jpeg、png、gif格式，大小：596 X 698px</em>
                    </div>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <img id="imgShow1" style="width: 294px; height: 345px" src="@Model.ProjectThumImage1" />
                    <input type="hidden" id="fileName1" name="ProjectThumImage1" value="@Model.ProjectThumImage1"/>
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>&nbsp;项目列表图片：</dt>
                <dd>
                    <div class="uploadImg">
                        <input type="button" id="btnUploadImg2" value="上传项目列表图片" class="button" /><em>支持jpg、jpeg、png、gif格式，大小：279 X 224px</em>
                    </div>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <img id="imgShow2" style="width: 279px; height: 224px" src="@Model.ProjectThumImage2" />
                    <input type="hidden" id="fileName2" name="ProjectThumImage2" value="@Model.ProjectThumImage2"/>
                </dd>
            </dl>
        </div>
        <div class="line30"></div>
        <div class="btn-list">
            <div>
                <input type="submit" class="button" id="btnnext" name="btnnext" value="下一步" />
            </div>
        </div>
    }
</div>

